home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- #
- # MBTask.c
- #
- # Example of an A/ROSE task, to be linked with "MBosmain.c.o"
- # and downloaded to a MCP card.
- #
- # Registers itself with
- # object_name "MBTask" and
- # type_name "MBServer".
- #
- # The "Exercise" application in this same folder will then find
- # this task on a MCP card, and use it for parallel processing
- # (if the "MCP" checkbox is checked).
- #
- # Components:
- # MBosmain.c
- # iter16.a
- # MBTask.c
- #
- ------------------------------------------------------------------------------*/
- /* -------------- MPW: select the following lines + <ENTER> ------
- Asm iter16.a
- C MBosmain.c
- C MBTask.c
- link -t 'DMRP' -c 'RWM ' ∂
- MBosmain.c.o ∂
- MBTask.c.o ∂
- iter16.a.o ∂
- ::OS.o ∂
- ::osglue.o ∂
- -o start
-
- ::Download start
- ---------------------------------------------------------------- */
-
-
-
- #define MBCODE 2000
-
- static char my_object_name [] = "MBTask";
- static char my_type_name [] = "MBServer";
-
-
-
- // definitions from "os.h":
-
- typedef long tid_type;
-
- struct mMessage
- {
- struct mMessage *mNext;
- long mId;
- short mCode;
- short mStatus;
- unsigned short mPriority;
- tid_type mFrom;
- tid_type mTo;
- unsigned long mSData [3];
- unsigned long mOData [3];
- long mDataSize;
- char *mDataPtr;
- };
-
- typedef struct mMessage mMessage;
-
- #define OS_MATCH_ALL 0 // on receive match anything
- #define OS_NO_TIMEOUT 0 // receive waits forever for message
-
- // some #define's from "managers.h":
-
- #define OS_UNKNOWN_MESSAGE (1<<8) // unrecognized message code
- #define Machine_Visible 0 // Register_task Machine visible flag
-
-
- // prototypes
-
- void MBTask();
- void myBitSet(char *pixStorage, long i);
- extern pascal short ITER16(short cx, short cy, short nmax);
-
- extern char Register_Task(char *, char *, short);
- extern void FreeMsg();
- extern mMessage *Receive(unsigned long, tid_type, unsigned short, long, ...);
- extern void SwapTID(mMessage *);
- extern void Send(mMessage *);
- extern char *AROSEGetMem();
- extern void AROSEFreeMem(char *);
- extern void AROSEBlockMove();
- extern short NetCopy(tid_type, void *, tid_type, void *, unsigned long);
-
- pascal void illegal () extern 0x4afc;
-
-
- struct MBparms {
- short nmax; // max. depth of iteration
- short d; // corresponding to coord. distance between pixels
- short cx, cy; // current point of the complex plane to be computed
- short yMCP; // line number (to be sent back to server)
- };
-
-
-
- //===============================
- void MBTask()
- //===============================
- {
- struct MBparms MBp; // these are the first 12 bytes of MBvariables, passed
- // along in m->mSData[0..2];
- short pixcnt, i;
- mMessage *m;
- char *pixStorage, *p;
-
- // message sent by client:
- // mCode = MBCODE
- // mSData[0..1] = 8 bytes of MBparms (first 8 bytes of MBvariables in "Exercise")
-
- // mDataSize = rowBytes => suppose rowBytes * 8 pixels !
- // mDataPtr = pointer to pixel line number MBp.cy of offscreen bitmap.
-
- // server gets local memory for storage of computed pixels
- // does NetCopy of local values back to mDataPtr
-
-
- if (!Register_Task (my_object_name, my_type_name, Machine_Visible))
- illegal (); // go debugging: something mysterious happens
-
- while(1) // forever !
- {
- m = Receive(OS_MATCH_ALL, OS_MATCH_ALL, OS_MATCH_ALL, OS_NO_TIMEOUT);
- if (m->mStatus != 0) // what happens?
- FreeMsg(m); // I don't know: better get rid of it
-
- switch (m->mCode) {
-
- case MBCODE:
-
- AROSEBlockMove((char *)&m->mSData[0], (char *)&MBp, 12L);
-
- pixcnt = 8 * m->mDataSize;
- p = AROSEGetMem(m->mDataSize); // get local linebuffer each time
- if (p == 0) illegal (); // (rather brutal error handling...)
- pixStorage = p;
- for (i=0; i<m->mDataSize; i++) *p++ = 0;
- for (i=0; i<pixcnt; i++) {
- if (ITER16(MBp.cx, MBp.cy, MBp.nmax) & 0x1)
- myBitSet(pixStorage, i);
- MBp.cx += MBp.d;
- }
-
- SwapTID(m);
- NetCopy(m->mFrom, pixStorage, m->mTo, m->mDataPtr, m->mDataSize);
- m->mCode++; // send back the result
- m->mOData[0] = MBp.yMCP;
- Send (m);
- AROSEFreeMem(pixStorage); // release local buffer each time
-
- break;
-
- default:
- m->mCode |= 0x8000; // unrecognized message code;
- m->mStatus = OS_UNKNOWN_MESSAGE;
- SwapTID(m);
- m->mCode++;
- Send (m);
- break;
- } // switch
-
- } // while (1)
-
- } // end MBTask()
-
-
-
- //===============================
- void myBitSet(char *pixStorage, long i)
- //===============================
- {
- long offset;
- short bitnb;
- char abyte, *p;
-
- offset = (i >> 3); // divide /8
- bitnb = i - 8*offset;
- abyte = 0x80 >> bitnb;
- p = pixStorage + offset;
- *p = *p | abyte;
- }
-